package org.beehoo.image;

import java.awt.Image;

import javax.swing.JComponent;

public class ImageDeal {

	public static Image getAppropriateImage(Image image,int initImageWidth,int initImageHeight,int canvasWidth,int canvasHeight){
		
		Image dealedImage = image;
		
		if (initImageWidth > canvasWidth||initImageHeight>canvasHeight) {

			int zoom = 0;
			//int scale = 0; 
			//boolean isWidth = true;
			if (initImageWidth < initImageHeight) {
				zoom = initImageHeight / canvasHeight;
				//scale = initImageHeight/initImageWidth;
				//isWidth = false;
			} else {
				zoom = initImageWidth / canvasWidth;
				//scale = initImageWidth /initImageHeight;
			}
			
			initImageWidth = initImageWidth / zoom;
			initImageHeight = initImageHeight / zoom;
			/*
			if(!isWidth){
                initImageHeight = initImageHeight - (initImageHeight-canvasHeight+40);
				initImageWidth = initImageWidth -(initImageHeight-canvasHeight+40)/scale;
			}else{
				initImageWidth=initImageWidth-(initImageWidth-canvasWidth+40);
				initImageHeight = initImageHeight-(initImageWidth-canvasWidth+40)/scale;
			}
			*/
		System.out.println(initImageWidth+":"+initImageHeight+"::"+canvasWidth+":"+canvasHeight);

			dealedImage = image.getScaledInstance(initImageWidth,
					initImageHeight, Image.SCALE_DEFAULT);

		}
		
		return dealedImage;
	}
}
